package dao.xml;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.thoughtworks.xstream.converters.SingleValueConverter;

public class DateConverter implements SingleValueConverter {
  
  private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm"); 

  public String toString(Object obj) {
    return sdf.format((Date) obj);
  }

  public Object fromString(String date) {
    try {
      return sdf.parse(date);
    }
    catch (ParseException e) {
      return null;
    }
  }

  @SuppressWarnings("unchecked")
  public boolean canConvert(Class type) {
    return type.equals(Date.class);
  }
}